﻿; (function (window, undefined, $) {
    var submiting = false;
    $('#frmEdit').validator({
        fields: {
            //'#MemberId': 'required',
            //'#MessTitle': 'required',
            //'#MessContent': 'required',
            //'#CreateTime': 'required',
            //'#ReplyContent': 'required',
            //'#ReplyUser': 'required'
        },
        valid: function (form) {
            if (submiting) {
                return;
            }
            submiting = true;
            FormSubmit(form, function (res) {
                if (res.Status > 0) {
                    layer.msg('操作成功！', 2, 9);
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);
                }
                else {
                    layer.msg('操作失败！' + res.Message, 2, 8);
                }
                submiting = false;
            })
        }
    });


    $("#btnSave").click(function (e) {
        var deptName = $("#DeptID").find("option:selected").text();
        $("#hideDeptName").val(deptName);
        $("#frmEdit").submit();
    });
    $("#btnClose").click(function () {
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    });

    $("#btnUploadImg").click(function () {


    });



    init();
    //初始化  
    function init() {

        //初始化图片上传  
        var btnImg = document.getElementById("btnUploadImg");
        var img = document.getElementById("imgShow");
        var hidImgName = document.getElementById("hidImgName");

        g_AjxUploadImg(btnImg, img, hidImgName);
    }


    var g_AjxTempDir = "/FileUpload/";

    //图片上传  
    function g_AjxUploadImg(btn, img, hidPut) {
        var button = btn, interval;
        new AjaxUpload(button, {
            action: options.uploadUrl,
            data: {},
            name: 'myfile',
            onSubmit: function (file, ext) {
                if (!(ext && /^(jpg|JPG|png|PNG|gif|GIF)$/.test(ext))) {
                    alert("您上传的图片格式不对，请重新选择！");
                    return false;
                }
            },
            onComplete: function (file, response) {
                flagValue = response;
                if (flagValue == "-1") {
                    alert("您上传的图片格式不对，请重新选择！");
                }
                else if (flagValue == "-2") {
                    alert("您上传的图片大于200K，请重新选择！");
                }
                else if (flagValue == "-3") {
                    alert("图片上传失败！");
                }
                else {
                    hidPut.value = response;
                    img.src = g_AjxTempDir + response;
                }
            }
        });
    }


})(window, undefined, jQuery);